﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccess;
using System.Data;

namespace DB.DataService
{
    public class ProductsService
    {
        DBDataProviderBase dbprovider = new DBDataProviderBase();
        MultiDBParameter commandParams = null;

        #region Catatalog 
        
        public bool InsertCatalog(string CatalogName)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "Cataloge_Name", CatalogName);
                return dbprovider.ExecuteNonQueryPro("InsertCataloge", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }

        }
        public bool DeleteCatalogeByID(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteNonQueryPro("DeleteCatalogeByID", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }

        }
        public bool UpdateCatalogeByID(int ID, string CatalogeName)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(2);
                commandParams.AddParameters(0, "ID", ID);
                commandParams.AddParameters(1, "Cataloge_Name", CatalogeName);
                return dbprovider.ExecuteNonQueryPro("UpdateCatalogeByID", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }
        }

        public DataSet GetAllCataloges()
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(0);
                return dbprovider.ExecuteDatasetPro("GetAllCataloge", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }

        public DataSet GetCatalogByID(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteDatasetPro("GetCatalogeByID", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }

        #endregion End Cataloges

        #region ProductType
        public bool InsertProductType(string ProductTypeName, int CatalogID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(2);
                commandParams.AddParameters(0, "ProductTypeName",ProductTypeName);
                commandParams.AddParameters(1, "CatalogId", CatalogID);
                return dbprovider.ExecuteNonQueryPro("InsertProductType", commandParams.Parameters);
                
            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool UpdateProductTypeById(int ID, string ProductTypeName, int CatalogID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(3);
                commandParams.AddParameters(0, "ID", ID);
                commandParams.AddParameters(1, "Product_Name",ProductTypeName);
                commandParams.AddParameters(2, "CatalogId", CatalogID);
                return dbprovider.ExecuteNonQueryPro("UpdateProductTypeById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool DeleteProductTypeById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteNonQueryPro("DeleteProductTypeById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }
        }
        public DataSet GetProductTypeById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteDatasetPro("GetProductTypeById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        public DataSet GetAllProductType()
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(0);
                return dbprovider.ExecuteDatasetPro("GetAllProductType", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        #endregion End ProductType
        #region Product
        public bool InsertProduct(string Name, string Introduction, string Description, string OriginalPrice,
                                  string Price1, string Origin, int Quantity, int Order, bool Active, int LanguageID, int ProductTypeId,
                                  string Price2, string DateInput, bool ActiveHot, bool ActiveNew, string PercentOff, bool ActiveOff, string ProductID)

        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(18);
                commandParams.AddParameters(0, "Name", Name);
                commandParams.AddParameters(1, "Introduction", Introduction);
                commandParams.AddParameters(2, "Description", Description);
                commandParams.AddParameters(3, "OriginalPrice", OriginalPrice);
                commandParams.AddParameters(4, "Price1", Price1);
                commandParams.AddParameters(5, "Origin", Origin);
                commandParams.AddParameters(6, "Quantity", Quantity);
                commandParams.AddParameters(7, "Order", Order);
                commandParams.AddParameters(8, "Active", Active);
                commandParams.AddParameters(9, "LanguageID", LanguageID);
                commandParams.AddParameters(10, "ProductTypeId", ProductTypeId);
                commandParams.AddParameters(11, "Price2", Price2);
                commandParams.AddParameters(12, "DateInput", DateInput);
                commandParams.AddParameters(13, "ActiveHot", ActiveHot);
                commandParams.AddParameters(14, "ActiveNew", ActiveNew);
                commandParams.AddParameters(15, "PercentOff", PercentOff);
                commandParams.AddParameters(16, "ActiveOff", ActiveOff);
                commandParams.AddParameters(17, "ProductID", ProductID);
                return dbprovider.ExecuteNonQueryPro("InsertProduct", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }    
        }
        public bool UpdateProductById(int ID, string Name, string Introduction, string Description, string OriginalPrice,
                                  string Price, string Origin, int Quantity, int Order, bool Active, int LanguageID, int ProductTypeId,
                                  string Price2, string DateInput, bool ActiveHot, bool ActiveNew, string PercentOff, bool ActiveOff)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(18);
                commandParams.AddParameters(0, "ID", ID);
                commandParams.AddParameters(1, "Name", Name);
                commandParams.AddParameters(2, "Introduction", Introduction);
                commandParams.AddParameters(3, "Description", Description);
                commandParams.AddParameters(4, "OriginalPrice", OriginalPrice);
                commandParams.AddParameters(5, "Price", Price);
                commandParams.AddParameters(6, "Origin", Origin);
                commandParams.AddParameters(7, "Quantity", Quantity);
                commandParams.AddParameters(8, "Order", Order);
                commandParams.AddParameters(9, "Active", Active);
                commandParams.AddParameters(10, "LanguageID", LanguageID);
                commandParams.AddParameters(11, "ProductTypeId", ProductTypeId);
                commandParams.AddParameters(12, "Price2", Price2);
                commandParams.AddParameters(13, "DateInput", DateInput);
                commandParams.AddParameters(14, "ActiveHot", ActiveHot);
                commandParams.AddParameters(15, "ActiveNew", ActiveNew);
                commandParams.AddParameters(16, "PercentOff", PercentOff);
                commandParams.AddParameters(17, "ActiveOff", ActiveOff);
                return dbprovider.ExecuteNonQueryPro("UpdateProductById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }    
        }
        public bool DeleteProductById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteNonQueryPro("DeleteProductById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }
        }
        public DataSet GetAllProduct()
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(0);
                return dbprovider.ExecuteDatasetPro("GetAllProduct", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        public DataSet GetProductById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteDatasetPro("GetProductById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        public DataSet GetRecordsSelectProduct(int from, int to)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(2);
                commandParams.AddParameters(0, "fromrecords", from);
                commandParams.AddParameters(1, "torecords", to);
                return dbprovider.ExecuteDatasetPro("GetRecordsSelectProduct", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        #endregion End Product
        #region Image
        public bool InsertImage(string Thumb, string Large, int ProductID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(3);
                commandParams.AddParameters(0, "Thumb", Thumb);
                commandParams.AddParameters(1, "Large", Large);
                commandParams.AddParameters(2, "ProductID", ProductID);
                return dbprovider.ExecuteNonQueryPro("InsertImage", commandParams.Parameters);

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool UpdateImageById(int ID, string Thumb, string Large, int ProductID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(4);
                commandParams.AddParameters(0, "ID", ID);
                commandParams.AddParameters(1, "Thumb", Thumb);
                commandParams.AddParameters(2, "Large", Large);
                commandParams.AddParameters(3, "ProductID", ProductID);
                return dbprovider.ExecuteNonQueryPro("UpdateImageById", commandParams.Parameters);

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool DeleteImageById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteNonQueryPro("DeleteImageById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }
        }
        public DataSet GetImageById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteDatasetPro("GetImageById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        #endregion End Image
        #region User
        public bool InsertUser(string UserName, string Password, string Email, string Address, string Phone)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(5);
                commandParams.AddParameters(0, "UserName", UserName);
                commandParams.AddParameters(1, "Password", Password);
                commandParams.AddParameters(2, "Email", Email);
                commandParams.AddParameters(3, "Address", Address);
                commandParams.AddParameters(4, "Phone", Phone);
                return dbprovider.ExecuteNonQueryPro("InsertUser", commandParams.Parameters);

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool UpdateUser(int ID, string UserName, string Password, string Email, string Address, string Phone)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(6);
                commandParams.AddParameters(0, "ID", ID);
                commandParams.AddParameters(1, "UserName", UserName);
                commandParams.AddParameters(2, "Password", Password);
                commandParams.AddParameters(3, "Email", Email);
                commandParams.AddParameters(4, "Address", Address);
                commandParams.AddParameters(5, "Phone", Phone);
                return dbprovider.ExecuteNonQueryPro("InsertUser", commandParams.Parameters);

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool DeleteUserById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteNonQueryPro("DeleteUserById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return false;
            }
        }
        public DataSet GetUserById(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteDatasetPro("GetUserById", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        public bool CheckUserNamePassword(string UserName, string Password)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(2);
                commandParams.AddParameters(0, "UserName", UserName);
                commandParams.AddParameters(1, "Password", Password);
                DataSet ds = new DataSet();
                ds =  dbprovider.ExecuteDatasetPro("CheckUserNamePassword", commandParams.Parameters);
                if (ds.Tables[0].Rows.Count > 0)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                return false;
            }
        }
        #endregion End 
        #region History
        public bool InsertHistoryProduct(string Price1, string Price2, int ProductID, int UserID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(4);
                commandParams.AddParameters(0, "Price1", Price1);
                commandParams.AddParameters(1, "Price2", Price2);
                commandParams.AddParameters(2, "ProductID", Price1);
                commandParams.AddParameters(3, "UserID", Price2);
                return dbprovider.ExecuteNonQueryPro("InsertHistoryProduct", commandParams.Parameters);

            }
            catch (Exception)
            {

                return false;
            }
        }
        public DataSet GetHistoryProductByID(int ID)
        {
            try
            {
                commandParams = new MultiDBParameter();
                commandParams.CreateParameters(1);
                commandParams.AddParameters(0, "ID", ID);
                return dbprovider.ExecuteDatasetPro("GetHistoryProductByID", commandParams.Parameters);
            }
            catch (Exception)
            {

                return null;
            }
        }
        #endregion EndHistory
    }
}
